import string
s=input()
k=int(input())
a=list(map(int, input().split()))
b=0
for i in range(len(s)):
p=string.ascii_lowercase.index(s[i])
b=b+a[p]*(i+1)
if k==0:
print(b)
else:
m=max(a)
c=list(range(len(s)+1,len(s)+k+1))
c1=[i * m for i in c]
b=b+sum(c1)
print(b)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
vector<int> v;
int main() {
string s;
int k, elm;
cin >> s;
cin >> k;
for (int i = 0; i < 26; ++i) {
cin >> elm;
v.push_back(elm);
}
int mx = *max_element(v.begin(), v.end());
ll res = 0;
for (int i = 0; i < s.length(); ++i) {
res = res + v[s[i] - 'a'] * (i + 1);
}
int j = s.length() + 1;
while (k--) {
res = res + j * mx;
++j;
}
cout << res;
return 0;
}
74. Search a 2D Matrix | 71. Simplify Path |
62. Unique Paths | 50. Pow(x, n) |
43. Multiply Strings | 34. Find First and Last Position of Element in Sorted Array |
33. Search in Rotated Sorted Array | 17. Letter Combinations of a Phone Number |
5. Longest Palindromic Substring | 3. Longest Substring Without Repeating Characters |
1312. Minimum Insertion Steps to Make a String Palindrome | 1092. Shortest Common Supersequence |
1044. Longest Duplicate Substring | 1032. Stream of Characters |
987. Vertical Order Traversal of a Binary Tree | 952. Largest Component Size by Common Factor |
212. Word Search II | 174. Dungeon Game |
127. Word Ladder | 123. Best Time to Buy and Sell Stock III |
85. Maximal Rectangle | 84. Largest Rectangle in Histogram |
60. Permutation Sequence | 42. Trapping Rain Water |
32. Longest Valid Parentheses | Cutting a material |
Bubble Sort | Number of triangles |
AND path in a binary tree | Factorial equations |